package com.example.myfragmentbase;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * create an instance of this fragment.
 */
public class BlankFragment2 extends Fragment {

    /**
     * 日志TAG
     */
    private static final String TAG = "BlankFragment2";

    private View root;

    private TextView tvHello;

    private Button btn;


    public BlankFragment2() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (root == null) {
            root = inflater.inflate(R.layout.fragment_blank1, container, false);
        }
        
        // 获取fragment布局文件中的控件
        tvHello = root.findViewById(R.id.tv_hello);
        btn = root.findViewById(R.id.btn);

        btn.setOnClickListener(v -> {
            // 打印日志
            Log.d(TAG, "onCreateView: 按钮点击~~~");
            // 修改TextView显示文字
            tvHello.setText("点我干啥？");
        });
        
        return root;
    }
}